package axelrod;

public class SimplePAgent implements AxelrodAgent {
    //number of turns the opponent defected
    private int noOfDefect;
    
    public SimplePAgent() {
        noOfDefect = 0;
    }

    public int getMove(int currentTurn, int opponentMove) {
        //update the probability of opponent defecting
        if(currentTurn != 0) {
            if(opponentMove == Environment.MOVE_DEFECT) {
                noOfDefect++;
            }
            double pd = noOfDefect / currentTurn;
            double gainDefect = (pd + (1 - pd) * 4) / 2;
            double gainCooperate = (1 - pd) * 3;
            if(gainDefect > gainCooperate) {
                return Environment.MOVE_DEFECT;
            } else {
                return Environment.MOVE_COOPERATE;
            }
        } else {
            return Environment.MOVE_COOPERATE;
        }
    }

    public void startMatch() {
        noOfDefect = 0;
    }
}
